package com.mvc.demo.bean;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 响应信息
 * @author hh
 * @date 2022/1/19
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseInfo<T> implements Serializable {

    private static final long serialVersionUID = 773672346926096198L;

    /**
     * 状态码
     */
    private int code;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    public static ResponseInfo fail(int code, String msg){
        return new ResponseInfo(code,
                msg,
                new JSONObject());
    }

    public static ResponseInfo fail(String msg){
        return new ResponseInfo(500,
                msg,
                new JSONObject());
    }
    public static <T> ResponseInfo success(T data){
        return new ResponseInfo(500,
                "success",
                data);
    }



}
